﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Aj.Core;

public partial class Manager_JobEdit : AuthPageBase
{
    protected int id;
    protected string Name;
    protected string NeedNum;
    protected int Shalary;
    protected string WorkingPlace;
    protected int RequiredDegree;
    protected int Sex;
    protected string Department;
    protected int WorkExperience;
    protected string EffectiveDate;
    protected string Description;

    protected DataSet ds = null;
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        try
        {
            id = QueryParamInt32("id");
            if (id > 0)
            {
                ds = CustomQuery.Job_GetJobById(id);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    Name = ds.Tables[0].Rows[0]["J_Name"].ToString();
                    NeedNum = ds.Tables[0].Rows[0]["J_NeedNum"].ToString();
                    Shalary = ds.Tables[0].Rows[0]["J_Shalary"].ToInt();
                    WorkingPlace = ds.Tables[0].Rows[0]["J_WorkingPlace"].ToString();
                    RequiredDegree = ds.Tables[0].Rows[0]["J_RequiredDegree"].ToInt();
                    Sex = ds.Tables[0].Rows[0]["J_Sex"].ToInt();
                    Department = ds.Tables[0].Rows[0]["J_Department"].ToString();
                    WorkExperience = ds.Tables[0].Rows[0]["J_WorkExperience"].ToInt();
                    object obj = ds.Tables[0].Rows[0]["J_EffectiveDate"];
                    EffectiveDate = DBNull.Value != obj && null != obj ? (obj.ToString().IsNotNullAndEmpty() ? obj.ToDateTime().ToString("yyyy-MM-dd") : "") : "";
                    Description = ds.Tables[0].Rows[0]["J_Description"].ToString();
                }
            }
            if (IsPost)
            {
                if (id > 0)   // 更新
                {
                    DateTime? effectiveDate = null;
                    if (!string.IsNullOrEmpty(FormParam("EffectiveDate")))
                    {
                        effectiveDate = Convert.ToDateTime(FormParam("EffectiveDate"));
                    }
                    int rel = CustomQuery.Job_Update(id, FormParam("Name"), FormParamInt32("NeedNum"), FormParamInt32("Shalary"), FormParam("WorkingPlace"), FormParamInt32("RequiredDegree"), FormParamInt32("Sex"), FormParam("Department"), FormParamInt32("WorkExperience"), FormParam("Description"), effectiveDate);
                    if (rel > 0)
                    {
                        Page_GoTo("JobList.aspx", true);
                    }
                    else
                    {
                        MessageBox("修改失败！");
                    }
                }
                else          // 新建
                {
                    DateTime? effectiveDate = null;
                    if (!string.IsNullOrEmpty(FormParam("EffectiveDate")))
                    {
                        effectiveDate = Convert.ToDateTime(FormParam("EffectiveDate"));
                    }
                    int rel = CustomQuery.Job_Add(FormParam("Name"), FormParamInt32("NeedNum"), FormParamInt32("Shalary"), FormParam("WorkingPlace"), FormParamInt32("RequiredDegree"), FormParamInt32("Sex"), FormParam("Department"), FormParamInt32("WorkExperience"), FormParam("Description"), effectiveDate);
                    if (rel > 0)
                    {
                        Page_GoTo("JobList.aspx", true);
                    }
                    else
                    {
                        MessageBox("新建失败！");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Utility.WriteErrorLog(ex);
        }
    }
}